<?php
namespace App\Http\Controllers\WebApi\User;

use App\Common\ErrorCode\ErrorCode;
use App\Exceptions\BusinessException;
use App\Http\Controllers\WebApi\BaseController;
use App\Http\Service\UserService;
use App\Http\Strategy\PersonalStrategy;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;

class PersonalController extends BaseController
{
    private $personalStrategy;

    public function __construct(
        PersonalStrategy $personalStrategy
    )
    {
        $this->personalStrategy = $personalStrategy;
    }

    /**
     * 设置员工类型
     * @param Request $request
     * @throws BusinessException
     */
    public function setStaffType(Request $request)
    {
        $this->webParamValidate(
            $request, [
                'cate' => [
                    'required',
                    Rule::in([1, 2])
                ]

            ]
        );

        $userInfo = UserService::getUserInfo();
        $userId = $userInfo['uid'];

        $this->personalStrategy->setType($userId, $request->post('cate'));
        $this->success();
    }
}